﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TravelSite.Entities
{
    public enum ContractStatus
    {
        Draft = 1,
        Sent = 2,
        Viewed = 3,
        Signed = 4
    }

    public class Contract
    {
        public int ContractId { get; set; }
        public DateTime? ContractDate { get; set; }
        public int ContactId { get; set; }
        public string ContactName { get; set; }
        public int AgentId { get; set; }
        public string AgentName { get; set; }
        public int TemplateId { get; set; }
        public string Status { get; set; }
        
        public string CardNumber { get; set; }
        public string CardDate { get; set; }
        public string CardCVV { get; set; }
        public string CardCC { get; set; }

        public ContractStatus StatusValue
        {
            get
            {
                return (ContractStatus)Enum.Parse(typeof(ContractStatus), Status);
            }
            set
            {
                Status = Enum.GetName(typeof(ContractStatus), value);
            }
        }

        public DateTime? ViewDate { get; set; }
        public string ViewIP { get; set; }
        public DateTime? SignedDate { get; set; }
        public string SignedIP { get; set; }

        public int PackageId { get; set; }
        public DateTime? ExpDate { get; set; }
        public int? VacationLength { get; set; }

        public string Signature 
        {
            get
            {
                if (StatusValue == ContractStatus.Signed)
                    return "Signed" + "<br/>" + Convert.ToDateTime(SignedDate).ToString("G") + "<br/>" + SignedIP;
                else if (StatusValue == ContractStatus.Viewed)
                    return "Viewed" + "<br/>" + Convert.ToDateTime(ViewDate).ToString("G") + "<br/>" + ViewIP;
                else
                    return "";
            }
        }

        public int? TravelId { get; set; }
        public string PackageStatus { get; set; }
        public string ComputedPackageStatus
        {
            get
            {
                if (PackageStatus != "AVAILABLE")
                    return PackageStatus;
                else if ((ExpDate.HasValue) && (VacationLength.HasValue) && ((ExpDate.Value - DateTime.Now.Date).TotalDays < VacationLength.Value))
                    return "EXPIRED";
                else
                    return "AVAILABLE";
            }
        }
        public bool AllowVerify
        {
            get
            {
                return !string.IsNullOrEmpty(PackageStatus);
            }
        }
    }

    public class ContractField
    {
        public const string FreeFormValue = "(free form)";
        public int ContractFieldId { get; set; }
        public int ContractId { get; set; }
        public int TemplateFieldId { get; set; }
        public string FieldName { get; set; }
        public string ContactColumnName { get; set; }
        public string ContactColumnFriendlyName { get; set; }
        public string ContactColumnCaption 
        {
            get
            {
                return string.IsNullOrEmpty(ContactColumnFriendlyName) ? FreeFormValue : ContactColumnFriendlyName;
            }
        }
        public string ContactColumnValue { get; set; }
    }
}
